package com.organization

import grails.test.*

class ProjectTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testConstraints() {
        def dep = new Department(name: "BU WAC")
        mockDomain(Department, [ dep ])
        def proj1 = new Project(name: "Proj1",startDate: new Date())
        def proj2 = new Project(name: "Proj2",startDate: new Date())
        mockDomain(Project, [ proj1, proj2 ])
        dep.addToProjects(proj1)
        dep.addToProjects(proj2)
        assertEquals 2,Project.findAll().size()

        def testProj = new Project(name: "P")
        assertFalse testProj.validate()
        assertEquals "size", testProj.errors["name"]
        assertEquals "nullable", testProj.errors["startDate"]

        testProj = new Project(department: dep, name: "Proj3", startDate: new Date());
        testProj.save()
        assertEquals 3,Project.findAll().size()
    }
}
